﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace GatewayDemo.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherForecastController> _logger;

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }

        [HttpGet]
        public IEnumerable<WeatherForecast> Get()
        {
            var profiler = new Stopwatch();
            profiler.Start();

            for (int i = 0; i < 10000; i++)
            {
                var result = md5("eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImEzck1VZ01Gdjl0UGNsTGE2eUYzekFrZnF1RSIsImtpZCI6ImEzck1VZ01Gdjl0UGNsTGE2eUYzekFrZnF1RSJ9.eyJpc3MiOiJodHRwczovL3Rzc28uY2xvdWRob3RlbHMuY24iLCJhdWQiOiIxMDAwMDAwNSIsImV4cCI6MTY0MTMwMzM1NSwibmJmIjoxNjQxMjk2MTU1LCJub25jZSI6IjYzNzc2ODkyOTQ2MzI0OTc5Mi5Oekl6WmpSbU9Ua3RNekZqTlMwME16UTVMVGxrWW1FdFlqRXhaV00xTURJME9HVXpPVFU0WkRnNE5tUXRNREV6WlMwME5UUmpMVGs1WTJZdE16QTNNV0kyWkdReE56Y3giLCJpYXQiOjE2NDEyOTYxNTUsImF0X2hhc2giOiJobG4yVHZjc2R2Y2tabnFRZGpiUVRBIiwic2lkIjoiNmJiYTI3MWIxMGFhODVmNjA1ZDFlOGYyYTAxMzg1NzAiLCJzdWIiOiJ7XCJ1c2VyaWRcIjpcIkhlbHBEZXNrXCIsXCJob3RlbGNkXCI6XCIwMjEwNDBcIixcInVzZXJuYW1lXCI6XCJcIixcImhvdGVsbmFtZVwiOl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eFtjp6tlTbyqAadft_os2bt-OmtnNzggp3ZN1Kdmvx0zVTs9T5zsQKP1YYrV65_TgHoij1c1t3z7vB0mqHFnPsiqkfewOOnWL2fXg50J0ush443dYMWF99zpm2Gjng2EAIdD-7IfIoOYh7zefGA");
            }
            profiler.Stop();
            var ss = profiler.ElapsedMilliseconds / 1000.0;
            var rng = new Random();
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary = Summaries[rng.Next(Summaries.Length)]
            })
            .ToArray();
        }

        public string md5(string str)
        {
            //32位大写
            using (var md5 = MD5.Create())
            {
                var result = md5.ComputeHash(Encoding.UTF8.GetBytes(str));
                return BitConverter.ToString(result);
            }
        }
    }
}